package com.itheima.app.controller;

import com.itheima.app.manager.SoulTestManager;
import com.itheima.vo.AnswerVo;
import com.itheima.vo.QuestionnaireVo;
import com.itheima.vo.SoulResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;
import java.util.Map;

@RestController
public class SoulTestController {

    @Autowired
    private SoulTestManager soulTestManager;

    /**
     *      测灵魂-问卷列表
     */
    @GetMapping("/testSoul")
    public List<QuestionnaireVo> findQuestionnaire(){
        return  soulTestManager.findQuestionnaire();
    }


    /**
     *      测灵魂-提交问卷
     */
    @PostMapping("/testSoul")
    public String commitQuestionnaire(@RequestBody Map<String,List<AnswerVo>> answers){
        //把问题与答案集拿出来，向后传递
        List<AnswerVo> answerList = answers.get("answers");
        return soulTestManager.commitQuestionnaire(answerList);
    }


   /**
    *    测灵魂-查看结果
    */
    @GetMapping("/testSoul/report/{id}")
    public SoulResultVo findResult(@PathVariable("id") String reportId){
        return soulTestManager.findResult(reportId);
    }

}
